import { Button, Divider, Dropdown, Menu, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import React, { useState, useRef, useEffect } from 'react'
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ProTable, { ProColumns, ActionType } from '@ant-design/pro-table';
import { connect, history } from 'umi';
import { queryRule, addInfo, updateInfo } from '../service'
import { employeeStateArray, socialTraineeStateArray } from '@/utils/constant';
import { findItemByTree } from '@/utils/functions';
import CreateForm from './components/CreateForm';
import moment from 'moment';

const TableList = (props) => {
  const actionRef = useRef();
  const [done, setDone] = useState(false);
  const [visible, setVisible] = useState(false);
  const [current, setCurrent] = useState(undefined);
  const { recruitment={} } = props
  const { options={} } = recruitment

  const itemEdit = (item) => {
    history.push(`/recruitment/employee/edit/${item.oid}`);
  };

  const itemDetail = (item) => {
    history.push(`/recruitment/employee/details/${item.oid}`);
  };

  const columns = [
    {
      title: '编号',
      dataIndex: 'id',
      hideInSearch: true,
    },
    {
      title: '发送时间',
      dataIndex: 'createTime',
      hideInSearch: true,
      render: (item) => {
        return item && moment(item).format('YYYY-MM-DD HH:mm:ss')
      },
    },
    {
      title: '邮件标题',
      dataIndex: 'title',
      hideInSearch: true,
    },
    {
      title: '收件人',
      dataIndex: 'name',
    },
    {
      title: '收件邮箱',
      dataIndex: 'receive',
    },
    {
      title: '附件地址',
      dataIndex: 'attachment',
      ellipsis: true,
      width: 400
    },
    {
      title: '发送人',
      dataIndex: 'sendName',
      hideInSearch: true,
    },
  ];

  const handleModalVisible = (value) => {
    setVisible(value);
  };

  const handleDone = () => {
    setDone(false);
    setVisible(false);
  };

  const handleCancel = () => {
    setVisible(false);
  };

  const handleSubmit = (values) => {
    const id = current ? current.id : '';
    setDone(true);
    setVisible(false);
    if (id) {
      updateInfo(values).then(() => {
        if (actionRef.current) {
          actionRef.current.reload();
        }
      });
    } else {
      addInfo(values).then(() => {
        if (actionRef.current) {
          actionRef.current.reload();
        }
      });
    }
  };

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="oid"
        request={(params) => queryRule(params)}
        columns={columns}

      />
      {/*<CreateForm*/}
      {/*  values={{}}*/}
      {/*  done={done}*/}
      {/*  current={current}*/}
      {/*  visible={visible}*/}
      {/*  onDone={handleDone}*/}
      {/*  onCancel={handleCancel}*/}
      {/*  onSubmit={handleSubmit}*/}
      {/*/>*/}
    </PageHeaderWrapper>
  );
};

export default connect(({ productAndCategory, loading, recruitment }) => ({
  productAndCategory,
  recruitment,
  loading: loading.models.productAndCategory,
}))(TableList);
